package cn.wolfcode.web.controller;

import cn.wolfcode.domain.Brand;
import cn.wolfcode.qo.QueryObject;
import cn.wolfcode.qo.pageResult;
import cn.wolfcode.service.IBrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @ClassName brandController
 * @Description TODO
 * @Author wdx
 * @Date 2023/4/1 10:29
 */
@Controller
@RequestMapping("/brand")
public class brandController {
    @Autowired
    private IBrandService brandService;

    @RequestMapping("/list")
    public String list(Model model, QueryObject qo){
        pageResult<Brand> pageResult = brandService.queryBrand(qo);
        model.addAttribute("pageResult",pageResult);
        return "brand/list";
    }
    @RequestMapping("/delete")
    public String delete(Long id){
        if(id != null){
            brandService.deleteByPrimaryKey(id);
        }
        return "redirect:/brand/list";
    }
    @RequestMapping("/input")
    public String input(Long id,Model model){
        if(id != null){
            Brand brand = brandService.selectByPrimaryKey(id);//通过id查询一条一条的数据
            model.addAttribute("brand",brand);
        }
        return "brand/input";
    }
    @RequestMapping("/saveOrupdate")
    public String saveOrupdate(Brand brand){
        if(brand.getId() != null){
            brandService.updateByPrimaryKey(brand);
        }
        else{
            brandService.insert(brand);
        }
        return "redirect:/brand/list";
    }
}
